
#ifndef _INI_READER__INCLUDED_
#define _INI_READER__INCLUDED_

#include <memory>
#include <string>
#include <vector>

#include "TemplateImpl/IniReaderImpl.h"

namespace nebula { namespace utility {

class IniReader
{
public:
	IniReader();
	IniReader(const std::string& filename);

public:
	bool parse(const char* filename);
	bool parse(const std::string &filename);

	bool is_good();

	bool get_bool(const char* section, const char* name, bool default_value = false);
	bool get_bool(const std::string &section, const std::string &name, bool default_value = false);

	int get_int(const char* section, const char* name, int default_value = 0);
	int get_int(const std::string &section, const std::string &name, int default_value = 0);

	std::string get_str(const char* section, const char* name, const char* default_value = 0);
	std::string get_str(const std::string &section, const std::string &name, const std::string &default_value = "");

	void get_sections(std::vector<std::string> &sections);

	void get_names(const char* section, std::vector<std::string> &names);
	void get_names(const std::string &section, std::vector<std::string> &names);

	//P should be like bool proc(const string& sectoin_name);
	//  and if return false, the iteration will be shut down
	template<typename P>
	void for_each_section(P& proc)
	{
		if (reader.get())
			reader->for_each_section(proc);
	}

protected:
	bool isGood;
	std::auto_ptr<IniReaderImpl> reader;
};

}} // namespace nebula::utility

#endif // _INI_READER__INCLUDED_

